package com.xueyu.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class MainFrame extends JFrame {

	private JPanel contentPane;
	private JDesktopPane desktopPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainFrame frame = new MainFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MainFrame() {
		setTitle("\u56FE\u4E66\u7BA1\u7406\u4E3B\u754C\u9762");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 960, 640);
		setExtendedState(JFrame.MAXIMIZED_BOTH);//最大化主界面
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnNewMenu = new JMenu("\u57FA\u672C\u6570\u636E\u7EF4\u62A4");
		mnNewMenu.setIcon(new ImageIcon(MainFrame.class.getResource("/image/base.png")));
		menuBar.add(mnNewMenu);
		
		JMenu menu_1 = new JMenu("\u56FE\u4E66\u7C7B\u522B\u7BA1\u7406");
		menu_1.setIcon(new ImageIcon(MainFrame.class.getResource("/image/bookTypeManager.png")));
		mnNewMenu.add(menu_1);
		
		JMenuItem menuItem_1 = new JMenuItem("\u6DFB\u52A0\u56FE\u4E66\u7C7B\u522B");
		menuItem_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				BookTypeAddInternalFrame btAddInternalFrame = new BookTypeAddInternalFrame();
				btAddInternalFrame.setVisible(true);
				desktopPane.add(btAddInternalFrame);
			}
		});
		menuItem_1.setIcon(new ImageIcon(MainFrame.class.getResource("/image/add.png")));
		menu_1.add(menuItem_1);
		
		JMenuItem menuItem_2 = new JMenuItem("\u7EF4\u62A4\u56FE\u4E66\u7C7B\u522B");
		menuItem_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				BookTypeManageInternalFrame btManageInternalFrame = new BookTypeManageInternalFrame();
				btManageInternalFrame.setVisible(true);
				desktopPane.add(btManageInternalFrame);
			}
		});
		menuItem_2.setIcon(new ImageIcon(MainFrame.class.getResource("/image/edit.png")));
		menu_1.add(menuItem_2);
		
		JMenu mnNewMenu_1 = new JMenu("\u56FE\u4E66\u7BA1\u7406");
		mnNewMenu_1.setIcon(new ImageIcon(MainFrame.class.getResource("/image/bookManager.png")));
		mnNewMenu.add(mnNewMenu_1);
		
		JMenuItem menuItem_3 = new JMenuItem("\u6DFB\u52A0\u56FE\u4E66");
		menuItem_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				BookAddInternalFrame bookAddInternalFrame = new BookAddInternalFrame();
				bookAddInternalFrame.setVisible(true);
				desktopPane.add(bookAddInternalFrame);
			}
		});
		menuItem_3.setIcon(new ImageIcon(MainFrame.class.getResource("/image/add.png")));
		mnNewMenu_1.add(menuItem_3);
		
		JMenuItem menuItem_4 = new JMenuItem("\u7EF4\u62A4\u56FE\u4E66");
		menuItem_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				BookManagerInternalFrame bookManagerInternalFrame = new BookManagerInternalFrame();
				bookManagerInternalFrame.setVisible(true);
				desktopPane.add(bookManagerInternalFrame);
			}
		});
		menuItem_4.setIcon(new ImageIcon(MainFrame.class.getResource("/image/edit.png")));
		mnNewMenu_1.add(menuItem_4);
		
		JMenuItem menuItem = new JMenuItem("\u5B89\u5168\u9000\u51FA");
		menuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int result = JOptionPane.showConfirmDialog(null, "是否退出系统");
				if(result == 0){
					dispose();					
				}
			}
		});
		menuItem.setIcon(new ImageIcon(MainFrame.class.getResource("/image/exit.png")));
		mnNewMenu.add(menuItem);
		
		JMenu menu = new JMenu("\u5173\u4E8E\u8F6F\u4EF6");
		menu.setIcon(new ImageIcon(MainFrame.class.getResource("/image/about.png")));
		menuBar.add(menu);
		
		JMenuItem menuItem_5 = new JMenuItem("\u5173\u4E8E\u8F6F\u4EF6");
		menuItem_5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				AboutFrame aboutframe = new AboutFrame();
				aboutframe.setVisible(true);
				desktopPane.add(aboutframe);
			}
		});
		menuItem_5.setIcon(new ImageIcon(MainFrame.class.getResource("/image/about.png")));
		menu.add(menuItem_5);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		desktopPane = new JDesktopPane();
		desktopPane.setBackground(Color.WHITE);
		contentPane.add(desktopPane, BorderLayout.CENTER);
		this.setLocationRelativeTo(null);//窗体居中
	}

}
